﻿﻿package UIComponents
{
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	/**
	 *快速购买UI 
	 * @author 邓坚
	 * 
	 */	
	public class UIfastBuy extends Sprite
	{
		/***末尾加1代表左边，2代表右边***/
		private var _txt1:TextField;			
		private var _txt2:TextField;
		private var _pic1:Sprite;
		private var _pic2:Sprite;
		//		private var _btn1_txt:TextField;
		//		private var _btn2_txt:TextField;
		private var _btn1:MyButton;
		private var _btn2:MyButton;
		
		private var _usebtn1:MyButton;			//使用按扭  没有为null;
		private var _usebtn2:MyButton;			
		private var _btnContainer1:DisplayObjectContainer;		//购买按扭容器  没有为null;
		private var _btnContainer2:DisplayObjectContainer;
		
		private var _buybtn1:MyButton;			//购买按扭;
		private var _buybtn2:MyButton;			
		
		private var _itemPrice1:TextField;		//左边购买按扭所需要的钱
		private var _itemPrice2:TextField;		//左边购买按扭所需要的钱
		
		public function UIfastBuy()
		{
			init();
		}
		
		public function init():void
		{
			_txt1		=	this.getChildByName("txt1") as TextField;
			_txt2		=	this.getChildByName("txt2") as TextField;
			
			//			_btn1_txt	=	this.getChildByName("btn1_txt") as TextField;
			//			_btn2_txt	=	this.getChildByName("btn2_txt") as TextField;
			_pic1		=	this.getChildByName("pic1") as Sprite;
			_pic2		=	this.getChildByName("pic2") as Sprite;
			
			
			_usebtn1	=	this.getChildByName("usebtn1") as MyButton;
			_usebtn2	=	this.getChildByName("usebtn2") as MyButton;
			
			_btnContainer1	=	(this.getChildByName("btnContainer1") as DisplayObjectContainer);
			_btnContainer2	=	(this.getChildByName("btnContainer2") as DisplayObjectContainer)
			if( null !=	 _btnContainer1){
				_itemPrice1			=	_btnContainer1.getChildByName("itemPrice") as TextField;
				_buybtn1			=  	_btnContainer1.getChildByName("buyBtn") as MyButton;
				
				if( null != _buybtn1)
					_buybtn1.buttonMode	=	true;
			}
			if( null !=	 _btnContainer2){
				_itemPrice2			=	_btnContainer2.getChildByName("itemPrice") as TextField;
				_buybtn2			=  	_btnContainer2.getChildByName("buyBtn") as MyButton;
				
				if( null != _buybtn2)
					_buybtn2.buttonMode	=	true;
				
			}
			//			_btn1		=	this.getChildByName("btn1") as MyButton;
			//			_btn2		=	(this.getChildByName("btnContainer") as DisplayObjectContainer).getChildByName("buyBtn") as MyButton;
			
			//			_itemPrice	=	(this.getChildByName("btnContainer") as DisplayObjectContainer).getChildByName("itemPrice") as TextField;
			
			if( null != _itemPrice1){
				_itemPrice1.selectable	=	false;
				_itemPrice1.mouseEnabled	= 	false;
			}
			if( null != _itemPrice2){
				_itemPrice2.selectable	=	false;
				_itemPrice2.mouseEnabled	= 	false;
			}
			addListener();
		}
		
		public function addListener():void
		{
			if( null != _usebtn1){
				_usebtn1.addEventListener(ComponentEvent.BUTTON_DOWN,usebtn1_clickHandler);
				_usebtn1.buttonMode	=	true;
			}
			
			if( null != _usebtn2){
				_usebtn2.addEventListener(ComponentEvent.BUTTON_DOWN,usebtn2_clickHandler);
				_usebtn2.buttonMode	=	true;
			}
			
			if( null != _btnContainer1){
				_btnContainer1.addEventListener(MouseEvent.CLICK, btnC1_clickHandler);
				//				_btnContainer1.buttonMode	=	true;
			}
			
			if( null != _btnContainer2){
				_btnContainer2.addEventListener(MouseEvent.CLICK, btnC2_clickHandler);
				//				_btnContainer2.buttonMode	=	true;
			}
			
			_txt1.autoSize	=	TextFieldAutoSize.LEFT;
			_txt2.autoSize	=	TextFieldAutoSize.LEFT;
			_txt1.wordWrap	=	_txt2.wordWrap	=	true;
			_txt1.selectable		=	_txt2.selectable		=	false;
			//_btn1_txt.selectable	=	_btn2_txt.selectable	=	false;
			//_btn1_txt.mouseEnabled	=	_btn2_txt.mouseEnabled	=	false;
		}
		
		/**
		 *设置左边购买中显中金币还是o币 
		 * @param mtype
		 * 
		 */
		public function setMoenyIcon1(mtype:String):void
		{
			( this._btnContainer1.getChildByName("qb_icoin") as DisplayObject).visible= mtype=="qb"?true:false;
			( this._btnContainer1.getChildByName("jb_icoin") as DisplayObject).visible= mtype=="jb"?true:false;
			( this._btnContainer1.getChildByName("obIcon") as DisplayObject).visible= mtype=="ob"?true:false;
		}
		
		/**
		 * 设置右边购买中显中金币还是o币 
		 * @param mtype
		 * 
		 */
		public function setMoenyIcon2(mtype:String):void
		{
			( this._btnContainer2.getChildByName("qb_icoin") as DisplayObject).visible= mtype=="qb"?true:false;
			( this._btnContainer2.getChildByName("jb_icoin") as DisplayObject).visible= mtype=="jb"?true:false;
			( this._btnContainer2.getChildByName("obIcon") as DisplayObject).visible= mtype=="ob"?true:false;
		}
		
		public function set itemPrice1(value:uint):void
		{
			if( null == _itemPrice1)return;
			_itemPrice1.text	=	value.toString();
		}
		
		public function set itemPrice2(value:uint):void
		{
			if( null == _itemPrice2)return;
			_itemPrice2.text	=	value.toString();
		}
		
		
		/**
		 *单击1按扭 
		 * @param e
		 * 
		 */
		public function usebtn1_clickHandler(e:Event):void
		{
			this.dispatchEvent(new PanelEvent("usebtn1Click",true));
		}
		/**
		 *单击2按扭  
		 * @param e
		 * 
		 */
		public function usebtn2_clickHandler(e:Event):void
		{
			this.dispatchEvent(new PanelEvent("usebtn2Click",true));
		}
		
		/**
		 *单击购买按扭1 
		 * @param e
		 * 
		 */
		public function btnC1_clickHandler(e:Event):void
		{
			this.dispatchEvent(new PanelEvent("btnC1Click",true));
		}
		/**
		 *单击2按扭  
		 * @param e
		 * 
		 */
		public function btnC2_clickHandler(e:Event):void
		{
			this.dispatchEvent(new PanelEvent("btnC2Click",true));
		}
		
		/**
		 *pic1相关 
		 */
		public function set spPic1(value:Sprite):void
		{
			while(_pic1.numChildren)_pic1.removeChildAt(0);
			if(null!=value){
				_pic1.addChild(value);
				value.width		=	80;
				value.height	=	80;
			}
		}
		public function addPic1(value:DisplayObject):void
		{
			if(null!=value){
				_pic1.addChild(value);
				value.width		=	80;
				value.height	=	80;
			}
		}
		public function get spPic1():Sprite
		{
			return _pic1;
		}
		
		
		/**
		 *pic2相关 
		 */
		public function set spPic2(value:Sprite):void
		{
			while(_pic2.numChildren)_pic2.removeChildAt(0);
			
			if(null!=value){
				_pic2.addChild(value);
				value.width		=	80;
				value.height	=	80;
			}
		}
		public function addPic2(value:DisplayObject):void
		{
			if(null!=value){
				_pic2.addChild(value);
				value.width		=	80;
				value.height	=	80;
			}
		}
		public function get spPic2():Sprite
		{
			return _pic2;
		}
		
		/**
		 *设置第lie列的文本 
		 * @param lie
		 * @param hitTxt
		 * @param btnTxt
		 * 
		 */
		public function setTxt(lie:uint,hitTxt:String):void
		{
			if(hitTxt!=null)
				(this["_txt"+lie] as TextField).text	=	hitTxt;
		}
		
		public function get useBtnLeft():MyButton
		{
			return this._usebtn1;
		}
		
		public function get useBtnRight():MyButton
		{
			return this._usebtn2;
		}
		
		public function get btnContainerLeft():DisplayObjectContainer
		{
			return this._btnContainer1;	
		}
		
		public function get btnContainerRight():DisplayObjectContainer
		{
			return this._btnContainer2;	
		}
		
		public function get buyBtnLeft():MyButton
		{
			return this._buybtn1;
		}
		
		public function get buyBtnRight():MyButton
		{
			return this._buybtn2;
		}
	}
}